package top.glike.funct.controller;

import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import top.glike.common.annotation.Log;
import top.glike.common.core.controller.BaseController;
import top.glike.common.core.domain.AjaxResult;
import top.glike.common.core.page.TableDataInfo;
import top.glike.common.enums.BusinessType;
import top.glike.common.utils.poi.ExcelUtil;
import top.glike.funct.domain.BedType;
import top.glike.funct.service.IBedTypeService;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 文件类别Controller
 *
 * @author Sophia
 * @date 2024-03-07
 */
@RestController
@RequestMapping("/bed/type")
public class BedTypeController extends BaseController {
    @Autowired
    private IBedTypeService bedTypeService;

    /**
     * 查询文件类别列表
     */
    @PreAuthorize("@ss.hasPermi('bed:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(BedType bedType) {
        startPage();
        List<BedType> list = bedTypeService.selectBedTypeList(bedType);
        return getDataTable(list);
    }
    
    /**
     * 查询所有文件类别列表
     */
    // @PreAuthorize("@ss.hasPermi('bed:type:list')")
    @GetMapping("/allList")
    public AjaxResult allList() {
        List<BedType> list = bedTypeService.selectBedTypeList(null);
        return AjaxResult.success(list);
    }

    /**
     * 导出文件类别列表
     */
    @PreAuthorize("@ss.hasPermi('bed:type:export')")
    @Log(title = "文件类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BedType bedType) {
        List<BedType> list = bedTypeService.selectBedTypeList(bedType);
        ExcelUtil<BedType> util = new ExcelUtil<BedType>(BedType.class);
        util.exportExcel(response, list, "文件类别数据");
    }

    /**
     * 获取文件类别详细信息
     */
    @PreAuthorize("@ss.hasPermi('bed:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(bedTypeService.selectBedTypeById(id));
    }

    /**
     * 新增文件类别
     */
    @PreAuthorize("@ss.hasPermi('bed:type:add')")
    @Log(title = "文件类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BedType bedType) {
        return toAjax(bedTypeService.insertBedType(bedType));
    }

    /**
     * 修改文件类别
     */
    @PreAuthorize("@ss.hasPermi('bed:type:edit')")
    @Log(title = "文件类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BedType bedType) {
        return toAjax(bedTypeService.updateBedType(bedType));
    }

    /**
     * 删除文件类别
     */
    @PreAuthorize("@ss.hasPermi('bed:type:remove')")
    @Log(title = "文件类别", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bedTypeService.deleteBedTypeByIds(ids));
    }
}
